package com.ruoyi.web.controller.resturant;

import com.ruoyi.ResBanner.domain.ResBanner;
import com.ruoyi.ResBanner.service.ResBannerService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Anonymous
@RestController
@RequestMapping("/api/resturant/banner")
@Api(tags = "轮播图管理")
public class ResBannerController {

    @Autowired
    private ResBannerService resBannerService;

    @ApiOperation("查询轮播图管理")
    @GetMapping("/listIf")
    //董虹妤2619
    public AjaxResult listIf(@RequestParam(value = "id",required = false)ResBanner resBanner){
        List<ResBanner> list = resBannerService.selectShopByIf(resBanner);
        return AjaxResult.success(list);
    }

    //新增轮播图
    @ApiOperation("新增轮播图")
    @PostMapping
    //董虹妤2619
    public AjaxResult add(@RequestBody ResBanner resBanner){
        return AjaxResult.success(resBannerService.insertResBanner(resBanner));
    }

    //修改轮播图
    @ApiOperation("修改轮播图")
    @PutMapping
    //董虹妤2619
    public AjaxResult edit(@RequestBody ResBanner resBanner){
        return AjaxResult.success(resBannerService.updateResBanner(resBanner));
    }

    //删除轮播图
    @ApiOperation("删除轮播图")
    @ApiImplicitParam(name = "id", value = "轮播图ID", required = true,dataType = "long",paramType = "path" ,dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    //董虹妤2619
    public AjaxResult remove(@PathVariable Long id){
        return AjaxResult.success(resBannerService.deleteResBanner(Math.toIntExact(id)));
    }
}
